package com.joca.scheduling.database;

import java.util.Date;
import java.util.LinkedList;
import java.util.List;

import com.joca.scheduling.entities.Role;
import com.joca.scheduling.entities.Schedule;
import com.joca.scheduling.entities.User;

public class ScheduleData {

	private List<Schedule> listOfSchedules;
	private static ScheduleData instance;

	private ScheduleData() {
		listOfSchedules = new LinkedList<Schedule>();

		Schedule sch = new Schedule();
		sch.setScheduleID(1);
		sch.setScheduleDate(new Date());
		sch.setReason("Razlog zasto je prihvaceno");
		sch.setDescription("Opis zahteva studenta");
	//	sch.setScheduleRequest(new User(2, "Pera", "Peric", "pera", "1", Role.Student));
	//	sch.setScheduleRespond(new User(1, "Jovan", "Dimitrijevic", "joca",
	//			"1", Role.Professor));

		addSchedule(sch);

		Schedule schedul = new Schedule();
		schedul.setScheduleID(2);
		schedul.setScheduleDate(null);
		schedul.setReason("");
		schedul.setDescription("Opis zahteva studenta");
	//	schedul.setScheduleRequest(new User(2, "Pera", "Peric", "pera", "1", Role.Student));
	//	schedul.setScheduleRespond(new User(1, "Jovan", "Dimitrijevic", "joca",
	//			"1", Role.Professor));

		addSchedule(schedul);

		Schedule sched = new Schedule();
		sched.setScheduleID(3);
		sched.setScheduleDate(null);
		sched.setReason("Razlog zasto je odbijeno");
		sched.setDescription("Opis zahteva studenta");
	//	sched.setScheduleRequest(new User(2, "Pera", "Peric", "pera", "1", Role.Student));
	//	sched.setScheduleRespond(new User(1, "Jovan", "Dimitrijevic", "joca",
	//			"1", Role.Professor));

		addSchedule(sched);
	}

	public static ScheduleData getInstance() {
		if (instance == null)
			instance = new ScheduleData();
		return instance;
	}

	public List<Schedule> getAllSchedules() {
		return listOfSchedules;
	}

	public void addSchedule(Schedule sch) {
		listOfSchedules.add(sch);
	}

/*	public List<Schedule> getSchedulesRequests(User user) {
		List<Schedule> listOfRequests = new LinkedList<Schedule>();

		for (Schedule sch : listOfSchedules) {
			if (user.getUserID() == sch.getScheduleRespond().getUserID()
					&& sch.getReason().equals("")) {
				listOfRequests.add(sch);
			}
		}
		return listOfRequests;
	}*/

	/*public List<Schedule> getScheduleResponses(User user) {
		List<Schedule> listOfResponses = new LinkedList<Schedule>();

		for (Schedule sch : listOfSchedules) {
			if (user.getUserID() == sch.getScheduleRespond().getUserID()
					&& !sch.getReason().equals("") && sch.getScheduleDate() != null) {
				listOfResponses.add(sch);
			}
		}
		return listOfResponses;
	}*/
	
	/*public List<Schedule> getScheduleResponsesForStudent(User user) {
		List<Schedule> listOfResponses = new LinkedList<Schedule>();

		for (Schedule sch : listOfSchedules) {
			if (user.getUserID() == sch.getScheduleRequest().getUserID()
					&& !sch.getReason().equals("") && sch.getScheduleDate() != null) {
				listOfResponses.add(sch);
			}
		}
		return listOfResponses;
	}*/
	

	public Schedule getScheduleByID(int scheduleID) {
		for(Schedule sch: listOfSchedules){
			if(sch.getScheduleID()==scheduleID)return sch;			
		}
		return null;
	}

}
